/**
 *====================================================
 * 文件名称: EnterpriseFinanceSummaryServiceImpl.java
 * 修订记录：
 * No    日期				作者(操作:具体内容)
 * 1.    2015年10月24日	chenxy(创建:创建文件)
 *====================================================
 * 类描述：(说明未实现或其它不应生成javadoc的内容)
 */
package com.yuexunit.finance.tatistics.service;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.yuexunit.finance.member.entity.lexicon.EnterpriseTypeEnum;
import com.yuexunit.finance.tatistics.entity.EnterpriseFinanceSummaryEntity;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.page.PageCriteria;
import com.yuexunit.page.PageList;
import com.yuexunit.persist.PersistUtil;
import com.yuexunit.persist.annotation.Transactional;

/**
 * @ClassName: EnterpriseFinanceSummaryServiceImpl
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author chenxy
 * @date 2015年10月24日 15:35:33
 */
@Implements(EnterpriseFinanceSummaryService.class)
public class EnterpriseFinanceSummaryServiceImpl implements EnterpriseFinanceSummaryService {

	@Override
	public PageList<EnterpriseFinanceSummaryEntity> inquireEnterpriseFinanceSummaryPageList(Long enterpriseId, Integer enterpriseType, PageCriteria page) {
		DetachedCriteria dc = DetachedCriteria.forClass(EnterpriseFinanceSummaryEntity.class);
		if (enterpriseId != null) {
			dc.add(Restrictions.eq("enterpriseId", enterpriseId));
		}
		if (enterpriseType != null) {
			dc.add(Restrictions.eq("enterpriseType", EnterpriseTypeEnum.valueOf(enterpriseType)));
		}
		dc.addOrder(Order.desc("creditLine"));
		return PersistUtil.get(dc, page);
	}
	
	@Override
	public List<EnterpriseFinanceSummaryEntity> inquireEnterpriseFinanceSummaryList(Long enterpriseId,
			Integer enterpriseType) {
		DetachedCriteria dc = DetachedCriteria.forClass(EnterpriseFinanceSummaryEntity.class);
		if (enterpriseId != null) {
			dc.add(Restrictions.eq("enterpriseId", enterpriseId));
		}
		if (enterpriseType != null) {
			dc.add(Restrictions.eq("enterpriseType", EnterpriseTypeEnum.valueOf(enterpriseType)));
		}
		return PersistUtil.get(dc);
	}

	@Override
	public Long createEnterpriseFinanceSummary(EnterpriseFinanceSummaryEntity entity) {
		PersistUtil.insert(entity);
		return entity.getEnterpriseId();
	}

	@Override
	@Transactional
	public void updateEnterpriseFinanceSummary(EnterpriseFinanceSummaryEntity entity) {
		PersistUtil.update(entity);
	}

	@Override
	public EnterpriseFinanceSummaryEntity inquireEnterpriseFinanceSummaryDetail(Long enterpriseId) {
		return PersistUtil.get(EnterpriseFinanceSummaryEntity.class, enterpriseId);
	}

	@Override
	@Transactional
	public void callProcedure() {
		PersistUtil.callProcedure("PRO_FIN_ENTERPRISE_FINANCE_SUMMARY", new ArrayList<Object>(), new ArrayList<Object>());
	}

	@Override
	@Transactional
	public void deleteEnterpriseFinanceSummary(Long enterpriseId) {
		PersistUtil.delete(EnterpriseFinanceSummaryEntity.class, enterpriseId);
	}
}
